<?php
class request {
	
	function addslashes($str){
	if(is_array($str)){
		foreach($str as $key =>$val) $str[$key] = addslashes($val);
	}else $str = addslashes($str);
		return $str;
	}
	
	function stripslashes($str){
		if(is_array($str)){
		foreach($str as $key=>$val) $str[$key] = stripslashes($val);
		}else $str = stripslashes($str);
		return $str;
	}
	
	function filter_html($str){
		return preg_replace(array(
				'/<(\/?)(script|i?frame|style|html|body|title|link|meta|object|param|embed|\?|\%)([^>]*?)>/isU',
				'/\s+/', '/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU',
				), array('\1\2', ' ', '',), $str);
	}
	
	function ip($tolong = false) {
		static $ip = null;
		if(!isset($ip)) {
			if($_SERVER["HTTP_X_FORWARDED_FOR"]) $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
			elseif($_SERVER["HTTP_CLIENT_IP"]) $ip = $_SERVER["HTTP_CLIENT_IP"];
			elseif($_SERVER["REMOTE_ADDR"]) $ip = $_SERVER["REMOTE_ADDR"];
			elseif(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
			elseif(getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
			elseif(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
			else $ip = "Unknown";
		}
		return $tolong ? ip2long($ip) : $ip;
	}
	
	function jump($url, $interval = 0, $target = '_self'){
		$str = "<meta http-equiv=\"refresh\" target=\"$target\" content=\"$interval; url=$url\">\n";
		if($interval > 0){
			$str .= "<script type=\"text/javascript\">setTimeout(\"location.href='$url';\", $interval*1000);</script>";
		}else{
			header("Location: $url");
			$str .= "<script type=\"text/javascript\">location.href='$url';</script>";
		}
		exit($str);
	}	
}
?>